<?php
/**
 * jewelrycontroller.php
 * 
 * Create on 2015-04-02
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\index;
use \haibao\cms\business\control\pc\entity\ArticleEntity;
class JewelryController extends IndexController{
	
	const JEWELRY_TAG = 6863;
	const WATCH_TAG = 7455;
		
	public function __construct($updateTime = null,$controlId,$isPublish){

		$this->conditionTagId = array(self::JEWELRY_TAG,self::WATCH_TAG); 
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 显示模版内容（模版动态数据的绑定和模版输出）
	 * @param : String $content
	 * @param : Array $controlData;
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		if($controlData['manual']){
			// 第一屏
			$this->getFirstActualData($controlData['manual']);
		}
		
		$this->assign('wordLinkList',$this->getWordLinkList($controlData['auto']));
		
		$this->assign('channelUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_JEWELRYWATCH));
		$this->assign('accessoryUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_ACCESSORY));
		$path = $this->generateHtmlPath(__CLASS__);
		$isNewHtml = $this->generateHtml($path,$content);

		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);
		return $content;
	}

	/**
	 * 调出规则：5个位置，调出珠宝腕表、配饰两个频道最新发布的5级资讯，按发布时间倒序显示
	 * @param : $dataCondition 数据条件
	 */
	public function getFirstActualData($dataCondition){
		
		$articleEntity = new ArticleEntity();
		$articleEntity->setLevel($dataCondition['level']);
		$articleEntity->setBigLevel($dataCondition['biglevel']);
		$articleEntity->setLimit($dataCondition['limit']);
		$articleEntity->setIsProImage(true);
		$articleEntity->setIsLeftJoinTag(true);
		$articleEntity->setIsPrimaryTag(false);
		$articleEntity->setIsConditionTag(true);
		$articleEntity->setIsReturnTag(true);
		$articleEntity->setIsImageColl(false);
		$articleEntity->setSource(__CLASS__);
		$articleEntity->setTagIds($this->conditionTagId);
		$articleEntity->setIsDebug(false);
		$articleEntity->setIsOnlyReturnPrimaryTag(true);
		$articleEntity->setProImageLevel(array(\haibao\cms\model\data\ArticleProImage::Level_FIVE,\haibao\cms\model\data\ArticleProImage::Level_SEVEN));

		$this->articleAction->setArticleEnity($articleEntity);
		list($articles,$articleProImages,$tagInfo,$articleTags) = $this->articleAction->getListForNew();
		$firstRightArticle = array();
		$articles = array_values($articles);
		foreach($articles as $key=>$article){
			$article->PublishTime = $this->formatDate($article->PublishTime->format('Y-m-d H:i:s'));
			switch($key){
				case 0:
					$firstLeftArticle = $article->toArray();
					$firstLeftArticle['Channel'] = self::getArticleUrl($article->PublishId,$articleTags[$article->Id]['ParentId']);
					$firstLeftArticle['TagName'] = $tagInfo[$articleTags[$article->Id]['TagId']]['TagName'];
					$firstLeftArticle['TagUrl'] = $tagInfo[$articleTags[$article->Id]['TagId']]['Url'];
					if(isset($articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_SEVEN])){
						$firstLeftArticle['ProImage'] = $articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_SEVEN];
					}else{
						$firstLeftArticle['ProImage'] = $articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO];
					}
					break;
				default:
					$firstRightArticle[$key] = $article->toArray();
					$firstRightArticle[$key]['TagName'] = $tagInfo[$articleTags[$article->Id]['TagId']]['TagName'];
					$firstRightArticle[$key]['TagUrl'] = $tagInfo[$articleTags[$article->Id]['TagId']]['Url'];
					$firstRightArticle[$key]['Channel'] = self::getArticleUrl($article->PublishId,$articleTags[$article->Id]['ParentId']);
					if(isset($articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_FIVE])){
						$firstRightArticle[$key]['ProImage'] = $articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_FIVE];
					}else{
						$firstRightArticle[$key]['ProImage'] = $articleProImages[$article->Id][\haibao\cms\model\data\ArticleProImage::Level_ZERO];
					}
					break;
			}
		}
		$firstRightArticle = array_values($firstRightArticle);
		$this->assign('firstLeftArticle',json_decode(json_encode($firstLeftArticle)));
		$this->assign('firstRightArticle', json_decode(json_encode($firstRightArticle)));
		//$this->assign('firstRightTwoArticle', json_decode(json_encode(array_slice($firstRightArticle,2,2))));
	}
}